<template>
  <div class="">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <ProFilter v-model="filter.pro_id" />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl">
          <SupplierSelect v-model="filter.sup_id" />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" prop="begin_time">
          <el-date-picker
            v-model="filter.begin_time"
            placeholder="开始时间"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            size="small"
            clearable
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" prop="end_time">
          <el-date-picker
            v-model="filter.end_time"
            placeholder="结束时间"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            size="small"
            clearable
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl">
          <el-input v-model="filter.describes" placeholder="描述" size="small" clearable />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button class="fl"  size="small" @click="app.resetFields($refs['filter'].$parent,'filter')">清 空</el-button>
          <el-button class="fl" type="primary" size="small" @click="getList()">查 询</el-button>
          <el-button class="fl" 
            type="primary"
            size="small"
            @click="handleDialog({dRef: 'payto', dTitle: '新增出纳付款', dType: 'add', dField: dFieldPayTo})"
          >新 增</el-button>
        </el-form-item>
      </el-form>
    </div> 
    <el-table v-loading="app.loading" class="search-table" :data="list" border 
      :summary-method="getSummaries"
      show-summary
      fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="公司名称" min-width="220px">
        <template slot-scope="{row}">
          <span v-if="row.company">{{ row.company }}</span>
        </template>
      </el-table-column>
      <el-table-column label="供应商" min-width="220px">
        <template slot-scope="{row}">
          <span v-if="row.sup_name">{{ row.sup_name }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="项目名称" min-width="260px" prop="pro_name" /> -->
      <el-table-column label="项目名称" min-width="220px">
        <template slot-scope="{row}">
          <span v-if="row.p_name">{{ row.p_name }}</span>
          <span v-else>{{ row.pro_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="付款总额" align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(row.money, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="待付款" align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(row.money - (row.pay_money ? row.pay_money : 0), 2) }}
        </template>
      </el-table-column>
      <el-table-column label="已付款" align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(row.pay_money, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="付款类型" width="110px" prop="v_type_name" />
      <el-table-column label="申请人" width="110px" prop="submitter_name" />
      <el-table-column label="申请时间" align="center" width="160px" prop="v_apply_time" />
      <el-table-column label="状态" width="80px" align="center" :formatter="formatterState" />
      <el-table-column label="备注" min-width="260px">
        <template slot-scope="{row}">
          <span v-if="row.type && row.type !== ''">类型：{{ row.type }}<br/></span>
          <span v-if="row.pay_time && row.pay_time !== ''">付款时间：{{ row.pay_time }}<br/></span>
          <span v-if="row.use_time && row.use_time !== ''">使用日期：{{ row.use_time }}<br/></span>
          <span v-if="row.return_time && row.return_time !== ''">归还日期：{{ row.return_time }}<br/></span>
          <span v-if="row.word && row.word !== ''">金额大写：{{ row.word }}<br/></span>
          <span v-if="row.addr && row.addr !== ''">使用工地：{{ row.addr }}<br/></span>
          <span v-if="row.detailed && row.detailed !== ''">订单明细：{{ row.detailed }}<br/></span>
          <span v-if="row.stage && row.stage !== ''">期别：{{ row.stage }}<br/></span>
          <span v-if="row.purpose && row.purpose !== ''">用途：{{ row.purpose }}<br/></span>
          <span v-if="row.speed && row.speed !== ''">小包进度：{{ row.speed }}<br/></span>
          <span v-if="row.basis && row.basis !== ''">付款依据：{{ row.basis }}<br/></span>
          <span v-if="row.condition && row.condition !== ''">付款条件：{{ row.condition }}<br/></span>
          <span v-if="row.cycle && row.cycle !== ''">付款周期：{{ row.cycle }}<br/></span>
          <span v-if="row.reason && row.reason !== ''">用途说明：{{ row.reason }}<br/></span>
          <span v-if="row.remark && row.remark !== ''">备注：{{ row.remark }}<br/></span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="90px" fixed="right">
        <template slot-scope="{row}">
          <el-dropdown>
            <el-button type="primary" size="mini">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleDialog({...row, ...{dRef: 'dialog', dTitle: '申请付款', dType: 'edit', dField: dField}})">确 认</el-dropdown-item>
              <el-dropdown-item
                @click.native="files({e_id: row.id, type: '',
                                      db_type: row.db_type })"
              >
                附 件
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    <Dialog ref="dialog" :get-data="getList" :info="dialog" />
    <PayTo ref="payto" :get-data="getList" :info="dialog" />
    <Cos ref="cos" :info="dialog" />
  </div>
</template>

<script>
import page from '@/utils/page'
import Dialog from './components/pay-dialog'
import { waits } from '@/api/finance/fund'
import SupplierSelect from '@/myComponents/SupplierSelect'
import ProFilter from '@/components/ProFilter'
import PayTo from './components/pay-to-dialog'

export default {
  name: '',
  components: { Dialog, SupplierSelect, ProFilter, PayTo },
  extends: page,
  props: {
    reqList: {
      default: waits,
      type: Function
    }
  },
  data() {
    return {
      price: {},
      parameter: { state: '0' },
      dField: ['account_id', 'money', 'id', 'payment_date', 'v_type', 'pay_money'],
      dFieldPayTo: ['id', 'account_id', 'pro_id', 'ctm_id', 'type', 'money', 'payment_date', 'remark', 'ctm_name']
    }
  },
  created() {
    this.getList()
  },
  methods: {
    formatterState(e) {
      let s = '未付款'
      if (e.state && e.state === 1) s = '已付款'
      return s
    },
    getListAfter(e) {
      this.price = e.summary
    },
    getSummaries() {
      const sums = []
      sums[0] = '合计'
      sums[4] = this.app.toFix(this.price.money, 2)
      sums[5] = this.app.toFix(this.price.money - this.price.pay_money, 2)
      sums[6] = this.app.toFix(this.price.pay_money, 2)
      return sums
    }
  }
}
</script>
<style scoped>
</style>
